package com.lipy.springootrabbitmq.config.topic;

import com.lipy.springootrabbitmq.config.RabbitMQConfig;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @description:
 * @author: lipy
 * @create: 2020-09-22 22:43
 **/
@Component
public class TopicSender {
    @Autowired
    RabbitTemplate rabbitTemplate;

    public void sendA() {
        String context = "hi, i am message A";
        System.out.println("Sender topic A : " + context);
        CorrelationData correlationData = new CorrelationData("A"+System.currentTimeMillis());
        this.rabbitTemplate.convertAndSend(RabbitMQConfig.TOPIC_EXCHANGE, "topic.A", context,correlationData);
    }

    public void sendB() {
        String context = "hi, i am message B";
        System.out.println("Sender topic B : " + context);
        this.rabbitTemplate.convertAndSend(RabbitMQConfig.TOPIC_EXCHANGE, "topic.B", context);
    }
}
